package meterMonitor.controller;

import meterMonitor.biz.MonitorDayBiz;
import meterMonitor.biz.MonitorDetailBiz;
import meterMonitor.consts.ResponseCode;
import meterMonitor.framework.auth.AuthorityType;
import meterMonitor.framework.auth.FireAuthority;
import meterMonitor.model.MonitorDetail;
import meterMonitor.vo.BaseResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RequestMapping("detailData")
@RestController
public class DetailDataController {
    public static final Logger logger = LoggerFactory.getLogger(DetailDataController.class);



    @Autowired
    MonitorDayBiz monitorDayBiz;

    @Autowired
    MonitorDetailBiz detailBiz;

    /**
     * 详细数据页面
     *
     * @param mv
     * @return
     */
    @RequestMapping("detailData.do")
    @FireAuthority(authorityTypes = AuthorityType.Query)
    private ModelAndView index(ModelAndView mv) {
        return mv;
    }

    @RequestMapping("queryAll.do")
    public BaseResponseData queryAll(String fromTime, String toTime, String meterCode) {
        BaseResponseData response = new BaseResponseData();
        try {
            List<MonitorDetail> monitorDetails = detailBiz.queryData(fromTime, toTime, meterCode);
            response.setCode(ResponseCode.SUCCESS);
            response.setData(monitorDetails);
        } catch (Exception e) {
            logger.error("查询异常信息失败！", e);
            response.setCode(ResponseCode.DATA_EXCEPTION);
            response.setMessage("查询异常信息失败！");
        }
        return response;
    }
}
